package com.example.administrator.basepro.ui.act;

import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.basepro.R;
import com.example.administrator.basepro.base.BaseActivity;
import com.example.administrator.basepro.model.bean.LoginBean;
import com.example.administrator.basepro.model.bean.TableOpeBean;
import com.example.administrator.basepro.ui.contract.SubmitSecureContract;
import com.example.administrator.basepro.ui.presenter.SubmitSecurePresenter;
import com.google.gson.Gson;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/9/1 0001.
 */

public class SubmitSecureActivity extends BaseActivity<SubmitSecurePresenter> implements SubmitSecureContract.View {
    @BindView(R.id.et_codenum)
    EditText et_codenum;

    @BindView(R.id.et_experience)
    EditText et_experience;

    @BindView(R.id.et_hangkongqi)
    EditText et_hangkongqi;

    @BindView(R.id.et_location)
    EditText et_location;

    @BindView(R.id.et_modelnum)
    EditText et_modelnum;

    @BindView(R.id.et_other)
    EditText et_other;

    @BindView(R.id.et_people)
    EditText et_people;

    @BindView(R.id.et_react)
    EditText et_react;

    @BindView(R.id.et_time)
    EditText et_time;

    @BindView(R.id.et_weather)
    EditText et_weather;

    @BindView(R.id.et_title)
    EditText et_title;
    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_submitsecure;
    }

    @Override
    protected void initEventAndData() {
    }
    Gson gson=new Gson();

    @OnClick(R.id.bt_commit)
    public void click(){
        TableOpeBean bean = getBean();
        String json = gson.toJson(bean);
        MediaType JSON= MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(JSON,json);

        if (et_title.getText().toString().isEmpty()){
            Toast.makeText(mContext, "请添加标题", Toast.LENGTH_SHORT).show();
        }else {
            mPresenter.submit(body);
        }
    }

    public TableOpeBean getBean(){
        TableOpeBean bean=new TableOpeBean();
        bean.setAboutPerson(et_people.getText().toString());
        bean.setCode(et_codenum.getText().toString());
        bean.setExperience(et_experience.getText().toString());
        bean.setHangkongqi(et_hangkongqi.getText().toString());
        bean.setModelNum(et_modelnum.getText().toString());
        bean.setOther(et_other.getText().toString());
        bean.setLocation(et_location.getText().toString());
        bean.setResult(et_react.getText().toString());
        bean.setTitle(et_title.getText().toString());
        bean.setWeather(et_weather.getText().toString());
        bean.setXianchang(et_react.getText().toString());
        bean.setTime(et_time.getText().toString());
        return bean;
    }

    @Override
    public void show(LoginBean msg) {
        // TODO: 2017/9/1 0001
        if (msg.isSuccess()){
            Toast.makeText(mContext, "提交成功", Toast.LENGTH_SHORT).show();
            finish();
        }else{
            Toast.makeText(mContext, "提交失败", Toast.LENGTH_SHORT).show();
        }
    }
}
